#include <bits/stdc++.h>
#define ll long long
#define F first
#define S second
#define N 100010
using namespace std;
int n,m;
ll len,lim,d[N],v[N],a[N],p[N];
bool cmp(pair<ll,ll> x,pair<ll,ll> y){return x.S==y.S?x.F<y.F:x.S<y.S;}
int main(){
	freopen("detect.in","r",stdin);
	freopen("detect.out","w",stdout);
	int T;
	scanf("%d",&T);
	while(T--){
		scanf("%d%d%lld%lld",&n,&m,&len,&lim);
		for(int i=0;i<n;i++) scanf("%lld%lld%lld",&d[i],&v[i],&a[i]);
		for(int i=0;i<m;i++) scanf("%lld",&p[i]);
		vector<pair<int,int> > rgs;
		for(int i=0;i<n;i++){
			if(a[i]>0){
				ll lo=d[i]+max(0ll,(lim*lim-v[i]*v[i]+a[i]*2)/(a[i]*2)),hi=len;
				if(lo<=hi){
					lo=lower_bound(p,p+m,lo)-p;
					hi=lower_bound(p,p+m,hi+1)-p-1;
					if(lo<=hi) rgs.push_back(make_pair(lo,hi));
				}
			}
			else if(a[i]==0){
				if(v[i]>lim){
					ll lo=d[i],hi=len;
					if(lo<=hi){
						lo=lower_bound(p,p+m,lo)-p;
						hi=lower_bound(p,p+m,hi+1)-p-1;
						if(lo<=hi) rgs.push_back(make_pair(lo,hi));
					}
				}
			}
			else{
				if(v[i]>lim){
					ll lo=d[i],hi=min(len,d[i]+(v[i]*v[i]-lim*lim-a[i]*2-1)/(-a[i]*2)-1);
					if(lo<=hi){
						lo=lower_bound(p,p+m,lo)-p;
						hi=lower_bound(p,p+m,hi+1)-p-1;
						if(lo<=hi) rgs.push_back(make_pair(lo,hi));
					}
				}
			}
		}
		sort(rgs.begin(),rgs.end(),cmp);
		int ans=m;
		for(int i=0,lst=-1;i<rgs.size();i++){
			if(rgs[i].F<=lst) continue;
			ans--;
			lst=rgs[i].S;
		}
		printf("%d %d\n",(int)rgs.size(),ans);
	}
	return 0;
}